package service

import (
	"github.com/jackc/pgx"
	"github.com/jinzhu/gorm"
	"gitlab.com/adapt-karaoke-project/backend/testutils"
	"gitlab.com/adapt-karaoke-project/backend/model"
)

func GetTestPoolDB() (*pgx.ConnPool, *gorm.DB) {
	db_cfg, err := testutils.GetDBConfigFromEnv()
	if err != nil {
		panic(err)
	}
	pool, err := pgx.NewConnPool(pgx.ConnPoolConfig{
		ConnConfig: pgx.ConnConfig{
			Host:      db_cfg.Address,
			Port:      db_cfg.Port,
			User:      db_cfg.Username,
			Password:  db_cfg.Password,
			Database:  db_cfg.Database,
			TLSConfig: nil,
		},
	})
	if err != nil {
		panic(err)
	}
	db, err := model.Open(db_cfg)
	if err != nil {
		panic(err)
	}
	return pool, db
}
